<?php

/*********************************************************************************
easyZenImport v.8b - Easy, Ajax Driven Importing Front-End For EasyPopulate 
Copyright (C) 11-02-06 Nick Van Dorsten
Author: Nick Van Dorsten <nickvd@gmail.com>

This library is free software; you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License as published by the Free Software
Foundation; either version 2.1 of the License, or (at your option) any later
version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.

You should have received a copy of the GNU Lesser General Public License along
with this library; if not, write to the Free Software Foundation, Inc., 
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
TODO: compress javascript into single file or at least pack them all...
*********************************************************************************/
require_once('inc/easyimport.cfg.php');
require_once('inc/app.top.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <title>easyZenImport</title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
      <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
      <link type="text/css" rel="stylesheet" href="css/easyzenimport.css" />
      <link type="text/css" rel="stylesheet" href="css/thickbox.css" />
      <script src="inc/jquery_.js" type="text/javascript"></script>
      <script src="inc/jquery.rounded.js" type="text/javascript"></script>
      <script src="inc/interface.js" type="text/javascript"></script>
      <script src="inc/jquery.thickbox.js" type="text/javascript"></script>
      <script src="inc/querystring.js" type="text/javascript"></script>
      <script type="text/javascript">
      //<![CDATA[
         var loading = {
            img: "images/loading.gif",
            off: true,
            show: function(){
               $('body').append('<div id="dc1"><div id="dc2"><img src="'+this.img+'" alt=""/><\/div><\/div>');
            },
            hide: function(){$('#dc1').remove();},
            toggle: function(){
               switch(this.off) {
                  case true:this.show();break;
                  case false:this.hide();break;
               }
               this.off = !this.off;
            }
         };
         
         function addToQueue(image,newid) {
            if (image) image = "<img src='" + image + "' alt=''/>";
            $('#queueCont').append('<div style="display:none;" id="queue_' + newid + '">'+image+'<a href="eazyImport.php?act=d&i=' + newid + '" class="btnDelete"><img src="images/editdelete.png" alt="Remove"/><\/a><span class="queuePrice">$ ' + $('#price').get(0).value + '<\/span><span class="queueName">' + $('#name').get(0).value + '<\/span><br/><span class="queueCat">'+$('#cat').get(0).value+'<\/span><\/div>');
            $('.stepCont').TransferTo({to: 'queue_'+newid,duration: 500,className: 'add2queue',complete:function(to){
               $(to).fadeIn(200).find('.btnDelete').click(deleteItem);
               $('#newForm').get(0).reset();
               loading.toggle(); //hide activity indicator
            }});
         };
         
         function deleteItem(x) {
            queryString.qsParse($(this).attr('href').split('?')[1]);
            if (queryString.get('act') == 'd') {
               var id = queryString.get('i');
               var txt = '';
               loading.show();
               $.ajax({
                  url: 'inc/ajax.php',
                  type: 'POST',
                  data: 'i='+id+'&act=d',
                  complete: loading.hide,
                  success: function(x){
                     $('#queue_'+id).css('position','absolute').Puff(500,function(){
                        $('#queueCont').html(x);
                        $('.btnDelete').click(deleteItem);
                     });
                  } // end success
               }); // end ajax call               
            } // end if
            return false;
         } // end deleteItem()
                  
         $(document).ready(function(){ 
            $('.stepCont').corner();
            $('#ajaxwrap').remove();
            $('#formFields').append($(document.createElement('iframe')).attr({src:'inc/ajaxupload.php',frameborder:'0',id:'iframe'}).get(0));
            $('.btnDelete').click(deleteItem);
         });
      //]]>
      </script>
   </head>
   <body>
   <?php if (!empty($errors)) echo "<div id='errorCont'>{$errors}</div>"; ?>
   <table id="onlyTable"><tr>
      <td id="left"><div id="formWrapper">
         <h1>Add New Product.</h1>
         <form action="eazyImport.php" id='newForm' method="post" enctype="multipart/form-data">
         <div class="stepCont">
            <fieldset id="formFields">
               <legend>Product Info</legend>
               <p>Please enter the product model, name, description, price, quantity, and category into the boxes provided below:</p>
               <label for="model">Model:</label><input type="text" name="model" class='xfer' id="model" value="" maxlength="50"/><br/>
               <label for="name">Name:</label><input type="text" name="name" class='xfer' id="name" value="" maxlength="50"/><br/>
               <label for="cat">Category:</label><select name="cat" class='xfer' id="cat"><?php echo getCatOptions(); ?></select><br/>
               <label for="price">Price:</label><input type="text" name="price" class='xfer' id="price" value="0.00" maxlength="12"/><br/>
               <label for="weight">Weight:</label><input type="text" name="weight" class='xfer' id="weight" value="0" maxlength="5"/><br/>
               <label for="quant">Quantity:</label><input type="text" name="quant" class='xfer' id="quant" value="1" maxlength="3"/><br/>
               <label for="desc">Description:</label><textarea name="desc" class='xfer' id="desc" rows="5" cols="45"></textarea>
               <div id='ajaxwrap'><label for="file">Image Upload:</label><input type="file" name="fileupload"/>
               <input type="submit" class="submit" value="Add Product To Queue" /></div>
            </fieldset>
         </div>
         </form>
      </div></td>
      <td id="right"><div id='queueWrapper'>
<!-- TODO: Get Rid Of width/height in markup, move to js, and look into using them to indicate ajax request and repond with a decent error message... -->
         <a href="eazyImport.php?height=100&amp;width=250&amp;reset=certainly" title="Clear Queue File?" class="thickbox" id="btnClear">Clear Queue File</a>
         <h1>Current Queue</h1>
         <div id="queueCont"><?php echo $queueContent ?></div>
      </div></td>
   </tr></table>   
   </body>
</html>